<?php

	echo '<table border="0" cellspacing="0" cellpadding="3">';

		$address = getcwd()."/filesystem/editor/usercolors.txt";

		$filehandler = fopen($address, "r");

		$content = fread($filehandler, filesize($address));
		$line = "";

		while(strlen($content)-strlen($line) > 0)
		{

			$line = strtok($content, ';');
			$content = substr($content, strlen($line)+1, strlen($content)-strlen($line));

			$red = strtok($line, ',');
			$line = substr($line, strlen($red)+1, strlen($line)-strlen($red));

			$green = strtok($line, ',');
			$line = substr($line, strlen($green)+1, strlen($line)-strlen($green));

			$blue = strtok($line, ';');
			$line = substr($line, strlen($blue)+1, strlen($line)-strlen($blue));

			addColor($red, $green, $blue);
		}

		fclose($filehandler);

	echo '</table>';

	function addColor($red, $green, $blue)
	{
		global $color_id;
		$color_id++;

		echo '<tr onMouseOver="mouseIn(\'color'.$color_id.'L\', \'color'.$color_id.'R\');" onMouseOut="mouseOut(\'color'.$color_id.'L\', \'color'.$color_id.'R\');">';
			echo '<td id="color'.$color_id.'L" width="50" background="./images/colorchooser_bg1.png">';
				echo '<table border="1" cellspacing="0" cellpadding="0"><tr><td bgcolor="'.getColor($red, $green, $blue).'"><img src="./images/1x1.gif" width="30" height="12");"/></td></tr></table>';
			echo '</td>';
			echo '<td id="color'.$color_id.'R" width="150" background="./images/colorchooser_bg2.png">';
				echo '#'.getColor($red, $green, $blue);
			echo '</td>';
		echo '</tr>';
		echo '<tr><td><img src="./images/1x1.gif" height="1"/></td><td></td><td></td></tr>';
	}

	function getColor($red, $green, $blue)
	{
		$red = round($red, 0);
		$green = round($green, 0);
		$blue = round($blue, 0);

		$color = getHex($red).getHex($green).getHex($blue);
		return $color;
	}

	function getHex($int)
	{
		$char[0] = '0';
		$char[1] = '1';
		$char[2] = '2';
		$char[3] = '3';
		$char[4] = '4';
		$char[5] = '5';
		$char[6] = '6';
		$char[7] = '7';
		$char[8] = '8';
		$char[9] = '9';
		$char[10] = 'A';
		$char[11] = 'B';
		$char[12] = 'C';
		$char[13] = 'D';
		$char[14] = 'E';
		$char[15] = 'F';

		$left = 0;
		$right = 0;

		while((16*$left+$right) < $int)
		{
			$right++;
			if($right > 15)
			{
				$left++;
				$right = 0;
			}
		}

		return $char[$left].$char[$right];
	}









?>